#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>

int ks[] = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 };
char cm[] = "10X98765432";

int validate(char* str){
	if (strlen(str) != 18) {
		return 0;
	}

	int sum = 0;
	for (int i = 0; i < 17; i++) {
		sum += (str[i]-'0') * ks[i];
	}

	if (str[17] == cm[sum % 11]) {
		return 1; 
	} else {
		return 0;
	}
}

int main() {
	int n;
	scanf("%d", &n);

	char buffer[32] = {0};

	while(n-- > 0) {
		scanf("%30s", buffer);
		puts(validate(buffer) ? "right" : "wrong");
	}
}